﻿using BCCommon;
using BCDto.TMS.Packing.PackingCategoryConfig;
using BCService.TMS.Packing.PackingCategoryConfig;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.Packing.PackingCategoryConfig
{
    /// <summary>
    /// 包装材料分类配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class PackingCategoryConfigController : ManagementBaseController
    {
        private readonly IPackingCategoryConfigService packingCategoryConfigService;

        public PackingCategoryConfigController(IPackingCategoryConfigService packingCategoryConfigService)
        {
            this.packingCategoryConfigService = packingCategoryConfigService;
        }

        /// <summary>
        /// 添加包装材料分类配置
        /// </summary>
        /// <param name="requestDto">包装材料分类信息</param>
        /// <response code="201">添加包装材料分类配置</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(PackingCategoryConfigDto), 201)]
        [Log("添加包装材料分类配置")]
        public IActionResult Post([FromBody] PackingCategoryConfigRequestDto requestDto)
        {
            var result = this.packingCategoryConfigService.Create(this.Admin, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改包装材料分类配置
        /// </summary>
        /// <param name="packingCategoryConfigId">包装材料分类配置Id</param>
        /// <param name="requestDto">包装材料分类信息</param>
        /// <response code="200">修改包装材料分类配置</response>
        /// <returns></returns>
        [HttpPut("{packing_category_config_id}")]
        [ProducesResponseType(typeof(PackingCategoryConfigDto), 200)]
        [Log("修改包装材料分类配置")]
        public IActionResult Put([FromRoute(Name = "packing_category_config_id")]int packingCategoryConfigId,
            [FromBody] PackingCategoryConfigRequestDto requestDto)
        {
            var result = this.packingCategoryConfigService.Update(this.Admin, packingCategoryConfigId, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除包装材料分类配置
        /// </summary>
        /// <param name="packingCategoryConfigId">包装材料分类配置Id</param>
        /// <response code="200">删除包装材料分类配置</response>
        /// <returns></returns>
        [HttpDelete("{packing_category_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除包装材料分类配置")]
        public IActionResult Delete([FromRoute(Name = "packing_category_config_id")] int packingCategoryConfigId)
        {
            this.packingCategoryConfigService.Delete(this.Admin, packingCategoryConfigId);
            return NoContent();
        }

        /// <summary>
        /// 获取包装材料分类配置
        /// </summary>
        /// <param name="packingCategory">包装材料分类</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取包装材料分类配置</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PackingCategoryConfigDto>), 200)]
        public IActionResult Query([FromQuery(Name = "packing_category")]string packingCategory,
            [FromQuery(Name = "create_start_date")]DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")]DateTime? createEndDate,
            [FromQuery(Name = "page_index")]int pageIndex = 1,
            [FromQuery(Name = "page_size")]int pageSize = 10)
        {
            var result = this.packingCategoryConfigService.Query(this.Admin, packingCategory, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取包装材料分类配置列表
        /// </summary>
        /// <response code="200">获取包装材料分类配置列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<PackingCategoryConfigDto>), 200)]
        public IActionResult List()
        {
            var result = this.packingCategoryConfigService.List(this.Admin);
            return this.Ok(result);
        }
    }
}
